<?php
class Tour
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }
    
    public function getTourDetails()
    {
    	$this->_db->query("SET NAMES 'utf8'");
    	$sql = $this->_db->fetchAll("
    		SELECT tour_id, tour_title, no_days, no_nights, tour_includes_en, tour_includes_ru, tour_excludes_en, tour_excludes_ru, tour_description_en, tour_description_ru  
    		FROM tours
    		WHERE status = 1");
    	
    	return $sql;
    }
    
    public function addTour($form_values)
    {
        $tour_title = $form_values['tour_title'];
        $tour_description_en = $form_values['tour_description_en'];
        $tour_description_ru = $form_values['tour_description_ru'];
        $no_days = $form_values['no_days'];
        $no_nights = $form_values['no_nights'];
        $tour_includes_en = $form_values['tour_includes_en'];
        $tour_includes_ru = $form_values['tour_includes_ru'];
        $tour_excludes_en = $form_values['tour_excludes_en'];
        $tour_excludes_ru = $form_values['tour_excludes_ru'];
        $status = $form_values['status'];        
        
        $this->_db->query("SET NAMES 'utf8'"); 
        $add_tour = $this->_db->exec("
                INSERT INTO tours (tour_title, no_days, no_nights, tour_includes_en, tour_includes_ru, tour_excludes_en, tour_excludes_ru, tour_description_en, tour_description_ru, status) 
                VALUES ('" . $tour_title . "', " . $no_days . ", " . $no_nights . ", '" . $tour_includes_en . "', '" . $tour_includes_ru . "', '" . $tour_excludes_en . "', '" . $tour_excludes_ru . "', '" . $tour_description_en . "', '" . $tour_description_ru . "', " . $status . ")
	    ");
        
        if($add_tour)
        {
            echo "Tour details has been successfully added.";
        }
    }
    
    public function getTourDetailsById($tour_id)
    {
    	$this->_db->query("SET NAMES 'utf8'");
    	$sql = $this->_db->fetchRow("
    		SELECT tour_title, no_days, no_nights, tour_includes_en, tour_includes_ru, tour_excludes_en, tour_excludes_ru, tour_description_en, tour_description_ru, status  
    		FROM tours
    		WHERE tour_id = " . $tour_id);
    	
    	return $sql;
    }
    
    public function updateTour($form_values)
    {
    	$tour_id = $form_values['tour_id'];
    	$tour_title = $form_values['tour_title'];
        $tour_description_en = $form_values['tour_description_en'];
        $tour_description_ru = $form_values['tour_description_ru'];
        $no_days = $form_values['no_days'];
        $no_nights = $form_values['no_nights'];
        $tour_includes_en = $form_values['tour_includes_en'];
        $tour_includes_ru = $form_values['tour_includes_ru'];
        $tour_excludes_en = $form_values['tour_excludes_en'];
        $tour_excludes_ru = $form_values['tour_excludes_ru'];
        $status = $form_values['status'];
        
       /* echo "UPDATE tours SET tour_title = '" . $tour_title . "', no_days = " . $no_days . " , no_nights = " . $no_nights . ", tour_includes = '" . $tour_includes . "', tour_excludes = '" . $tour_excludes . "', tour_description = '" . $tour_description . "', status = " . $status . "
        	WHERE tour_id = " . $tour_id;
        
        exit;*/
        $this->_db->query("SET NAMES 'utf8'");
        $update_tour = $this->_db->exec("
        	UPDATE tours SET tour_title = '" . $tour_title . "', no_days = " . $no_days . " , no_nights = " . $no_nights . ", tour_includes_en = '" . $tour_includes_en . "', tour_includes_ru = '" . $tour_includes_ru . "', tour_excludes_en = '" . $tour_excludes_en . "', tour_excludes_ru = '" . $tour_excludes_ru . "', tour_description_en = '" . $tour_description_en . "', tour_description_ru = '" . $tour_description_ru . "', status = " . $status . "
        	WHERE tour_id = " . $tour_id);
        
        if($update_tour)
        {
        	echo "Tour details has been successfully updated.";
        }
    }
    
    public function deleteTour($tour_id)
    {
    	$del_tour = $this->_db->exec("
    		DELETE FROM tours
    		WHERE tour_id = " . $tour_id
    	);
    	
    	if($del_tour)
    	{
    		echo "Selected tour has been successfully deleted.";
    	}
    }
} 
?>